<?php
namespace app\admin\validate;

use think\Validate;

class User extends Validate
{
    protected $rule = [
        'username'  => 'require|length:3,20|unique:user',
        'password'  => 'require|length:6,20',
        'nickname'  => 'require|length:2,20',
        'email'     => 'email',
        'mobile'    => 'mobile',
        'status'    => 'require|in:0,1'
    ];

    protected $message = [
        'username.require'  => '用户名不能为空',
        'username.length'   => '用户名长度必须在3-20个字符之间',
        'username.unique'   => '用户名已存在',
        'password.require'  => '密码不能为空',
        'password.length'   => '密码长度必须在6-20个字符之间',
        'nickname.require'  => '昵称不能为空',
        'nickname.length'   => '昵称长度必须在2-20个字符之间',
        'email'            => '邮箱格式不正确',
        'mobile'           => '手机号格式不正确',
        'status.require'   => '状态不能为空',
        'status.in'        => '状态值不正确'
    ];

    protected $scene = [
        'add'      => ['username', 'password', 'nickname', 'email', 'mobile', 'status'],
        'edit'     => ['nickname', 'email', 'mobile', 'status'],
        'login'    => ['username', 'password'],
        'register' => ['username', 'password', 'nickname'],
        'update'   => ['nickname', 'email', 'mobile']
    ];
} 